﻿using FastCloud.Base.Config;
using FastCloud.Base.Desgin;
using FastCloud.Base.Entity;
using FastIOC.Attribute;
using FastORM.Entity;
using FastUtil.Convert;
using FastUtil.Data;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastCloud.Base.DB
{
    public class DB_Group : BaseDBML<Frame_Group>
    {
        public override void Insert(Frame_Group Entity)
        {
            if (string.IsNullOrEmpty(Entity.GroupGuid))
            {
                Entity.GroupGuid = GenerateUtil.GenerateUnitGuid();
            }
            Entity.AddDate = DateTime.Now;
            base.Insert(Entity);
        }

        public bool ExistGroup(string GroupTag)
        {
            List<ParamEntity> ParamList = new List<ParamEntity>() { new ParamEntity() { ParamName = "GroupTag", ParamValue = GroupTag } };
            return SelectCount("GroupTag=@GroupTag", ParamList) > 0;
        }

        public bool ExistGroup(string GroupGuid, string GroupTag)
        {
            List<ParamEntity> ParamList = new List<ParamEntity>() { new ParamEntity() { ParamName = "GroupGuid", ParamValue = GroupGuid },
                new ParamEntity() { ParamName = "GroupTag", ParamValue = GroupTag } };
            return SelectCount("GroupTag=@GroupTag and GroupGuid!=GroupGuid", ParamList) > 0;
        }
    }
}
